﻿/**
 * @file service_timer_base.hpp
 * @date 2021/07/27 19:07
 * 
 * @author harrybao (harrybao@123u.com)
 * 
 * @brief 服务定时
 * 
 * @version v1.0.0
 * 
 * @copyright Copyright © 2021 All Rights Reserved 上海欢乐互娱网络科技有限公司
 * 
 * @par history:
 * <table>
 * <tr><th>Date                     <th>Version     <th>Author      <th>Description
 * <tr><td>2021/07/27 19:07         <td>1.0.0       <td>harrybao    <td>创建初始版本
 * </table>
 */

#pragma once

#include <cinttypes>
#include "time/service_time_scheduler.hpp"

namespace guild_service {
namespace detail {

/**
 * @brief 定时器类型
 * 
 */
enum class timer_type {
  TIMER_TYPE_ONCE = 0,
  TIMER_TYPE_LOOP
};

/**
 * @brief 服务定时基类
 * 
 */
class service_timer_base {
public:
  // friend class ServiceTimerMgr;
public:
  service_timer_base() : m_handle(kInvalidTimeHandler) {}
  virtual ~service_timer_base() {}
  /**
   * @brief 开启定时器
   * 
   * @return true 
   * @return false 
   */
  bool start() {
    return true;
  }

  /**
   * @brief 定时回调
   * 
   * @return true 
   * @return false 
   */
  virtual bool timer_callback(uint64_t, time_t) = 0;
  
  /**
   * @brief 
   * 
   * @return time_t 
   */
  virtual time_t duration() = 0;

  /**
   * @brief 
   * 
   * @return timer_type 
   */
  virtual timer_type type() = 0;

public:
  /**
   * @brief Set the handle object
   * 
   * @param handle 
   */
  void set_handle(time_scheduler_handler_type handle) {
    m_handle = handle;
  }
  
  /**
   * @brief Get the handle object
   * 
   * @return time_scheduler_handler_type 
   */
  time_scheduler_handler_type get_handle() {
    return m_handle;
  }

  /**
   * @brief 定时是否已经开启
   * 
   * @return true 
   * @return false 
   */
  bool started() const {
    return true;
  }
  
  /**
   * @brief 关闭定时器
   * 
   * @return true 
   * @return false 
   */
  bool stop() {
    return true;
  }
private:
  time_scheduler_handler_type m_handle;
};

}  // namespace detail
}  // namespace guild_service